package org.easy.web.config;

import lombok.extern.slf4j.Slf4j;
import org.easy.exception.EasySshException;
import org.easy.exception.FileMonitorException;
import org.easy.exception.GeneratorException;
import org.easy.exception.SqlException;
import org.easy.tool.res.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: 全局异常处理
 * @Author: wxl
 * @CreateTime: 2022/12/28 8:58
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = FileMonitorException.class)
    public Result<?> fileMonitorException (FileMonitorException e) {
        log.info("异常信息:{}",e.getMessage());
        return Result.failed(e.getMessage());
    }

    @ExceptionHandler(value = SqlException.class)
    public Result<?> sqlException (SqlException e) {
        log.info("异常信息:{}",e.getMessage());
        return Result.failed(e.getMessage());
    }

    @ExceptionHandler(value = GeneratorException.class)
    public Result<?> generatorException (GeneratorException e) {
        log.info("异常信息:{}",e.getMessage());
        return Result.failed(e.getMessage());
    }

    @ExceptionHandler(value = EasySshException.class)
    public Result<?> sshException (EasySshException e) {
        log.info("异常信息:{}",e.getMessage());
        return Result.failed(e.getMessage());
    }


}
